home *** CD-ROM | disk | FTP | other *** search
- ; NAME sum
- ; PURPOSE sums the numbers 0 to number1
- ; DESIGN
- ; result <- 0
- ; load number1
- ; for number1 <- number1 downto 0
- ; add number1 to result
- ; end for
- ; store result in number3
- ; NOTE
- ; sum to 50000 is maximum without overflow
- ; on arm 2 this takes 0.076 seconds
-
-
-
-
-
-
- ldr r7, [r1] ; load number 1 to r7
- mov r8, #0 ; set result r8 to zero
- .loop
- add r8, r8, r7 ; add number to result
- sub r7, r7, #1 ; decrement the number
- cmp r7, #0 ; has the number reached zero
- bge loop ; branch if its greater than zero back round the loop
- str r8, [r3] ; store the result in number 3
-
-